using System;
using System.Data;
using System.Drawing;
using System.Threading;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Data;

namespace Dimok.Aspx.Manager.Lib.Controls {
	public partial class TrackerRequest : System.Web.UI.UserControl {
		#region HTML Controls
		#endregion
		public int TrackerRequestID = 0;
		public string VIN = "";
		protected void Page_Load(object sender, System.EventArgs e) {
			try{
				UOX.TrackerClass tracker = null;
				UOX uox = new UOX();
				if( TrackerRequestID == 0 )TrackerRequestID = UOX.GetQueryParamInt("TrackerRequestID");
				if( VIN == "" )VIN = UOX.QueryParam.VIN;
				if( TrackerRequestID > 0 )tracker = uox.Tracker(TrackerRequestID);
				else if( VIN != "" ) tracker = uox.Tracker(VIN,true);
				else if( uox.ApplID0 > 0 )tracker = uox.Tracker(uox.LoanInfo.VIN,uox.LoanInfo.DealerID,false);
				else tracker = uox.Tracker(true);
				
				if( TrackerRequestID == 0 )
					Context.Response.Redirect(Page.Request.Path+"?TrackerRequestID="+tracker.TrackerRequestID,true);

				ltrTechRating.Text = tracker.TechniciansByDistance().GetXml();
				ltrTrackerRequest.Text = tracker.XmlInnerText();
				SQL.SELECT(selTechnician,uox.Tracker().Technicians(),"NameShort","ID");
				ltrTechTrackers.Text = SQL.BuildSelectOptions(tracker.Technician_Trackers().Tables[0],"TrackerID","","style");
				SQL.SELECT(selRequestStatus,tracker.RequestStatusList(),"MenuName","MenuID");
				SQL.SELECT(selDealers,UOX.dbRaw,SQL.Dealers_V,"Name","ID");
				ltrTrackerRequestNotes.Text = tracker.RequestNotes().GetXml();
				ltrTrackerRequestNotesList.Text = UOX.TrackerClass.RequestNotesList().GetXml();
				ltrTrackers.Text = tracker.Trackers().GetXml();
				adoTechRequests.Text = tracker.Technician_Requests();
				car.VIN = tracker.VIN;
				ltrScript.Text += @"<SCRIPT>
var selRequestStatus="+selRequestStatus.ClientID+@";
var selselDealers="+selDealers.ClientID+@";
var selTechnician="+selTechnician.ClientID+@";
"+			(tracker.Warning == "" ? "" : "alert('"+tracker.Warning.Replace("'","\\'").Replace("\r\n","\\\n")+@"');") + @"
</SCRIPT>
";
				trackerTrans.TrackerRequestID = tracker.TrackerRequestID;
			}catch(ThreadAbortException){
			}catch(UOX.TrackerClass.VinProblemException exc){
				Visible = false;
				Response.Write("<pre><h3>"+exc.Message+"</h3></pre>");
				Response.End();
			}catch(Exception exc){throw new Dimok.Exceptions.ClientException(exc);}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e) {
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent() {
		}
		#endregion
	}
}
